<?php
	// 获取传过来的值
	$flag = $_POST["flag"];
	$mysql = new mysqli("localhost","root","","yihe");
	if($mysql -> connect_error){
		exit("数据库链接是失败,错误信息是:{$mysql -> connect_error}");
	}
	$mysql -> set_charset("utf8");
	switch ($flag) {
		case 'select':
		{
			select();
			
			break;
		}
		case 'insert':
		{
			insert();
			break;
		}
		default:
			break;
	}
	function select(){
		global $mysql;
		$user_phone = $_POST["user_phone"];
		$select_sql = "select * from user_info where user_phone = '{$user_phone}'";
		$result = $mysql -> query($select_sql);
		// 判断是否查询到数据
		if($result -> num_rows){
			echo "1";
		}else{
			echo "0";
		}
	}
	function insert(){
		global $mysql;
		$user_phone = $_POST["user_phone"];
		$user_pass = $_POST["user_pass"];
		$insert_sql = "insert into user_info (user_phone, user_pass) values ('{$user_phone}', '{$user_pass}')";
		$result = $mysql -> query($insert_sql);
		if ($result) {
			echo "1";
		} else {
			echo "0";
		}
	}
	// 关闭数据库
	$mysql -> close();
?>